<?php
/*
  $Id: categories.php,v 1.146 2003/07/11 14:40:27 hpdl Exp $

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2003 osCommerce

  Released under the GNU General Public License
*/

  require('includes/application_top.php');

  require(DIR_WS_CLASSES . 'currencies.php');
  $currencies = new currencies();

  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');

  if (isset($HTTP_GET_VARS['gID']) && ($HTTP_GET_VARS['gID'] != '')) {
    $gID = $HTTP_GET_VARS['gID'];
  }
  
  if (tep_not_null($action)) {
    switch ($action) {
      case 'edit':
	    $gID = $HTTP_POST_VARS['gift_card_id'];
		//echo $gID;
		$gAmount = $HTTP_POST_VARS['gc_new_amount'];
		//echo '<br>'.$gAmount;
		$gEnabled = $HTTP_POST_VARS['gc_enable'];
		if ($gEnabled == 'enable') {
		  $gEnableFlag = '1';
		} else {
		  $gEnableFlag = '0';
		}
		//echo '<br>'.$gEnabled;
		$update_query = tep_db_query("update `".TABLE_GIFT_CARDS."` set gift_cards_amount_remaining='".$gAmount."', gift_cards_enabled='".$gEnableFlag."' where gift_cards_id='".$gID."'");
        break;
	  default:
        break;
    }
  }

// check if the catalog image directory exists
  if (is_dir(DIR_FS_CATALOG_IMAGES)) {
    if (!is_writeable(DIR_FS_CATALOG_IMAGES)) $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_NOT_WRITEABLE, 'error');
  } else {
    $messageStack->add(ERROR_CATALOG_IMAGE_DIRECTORY_DOES_NOT_EXIST, 'error');
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/general.js"></script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onload="SetFocus();">
<div id="spiffycalendar" class="text"></div>
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
    <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
    </table></td>
<!-- body_text //-->
    <td width="100%" valign="top">
	<table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
            <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
            <td align="right"><table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('search', FILENAME_CATEGORIES, '', 'get');
    echo HEADING_TITLE_SEARCH . ' ' . tep_draw_input_field('search');
    echo '</form>';
?>
                </td>
              </tr>
              <tr>
                <td class="smallText" align="right">
<?php
    echo tep_draw_form('goto', FILENAME_CATEGORIES, '', 'get');
    echo HEADING_TITLE_GOTO . ' ' . tep_draw_pull_down_menu('cPath', tep_get_category_tree(), $current_category_id, 'onChange="this.form.submit();"');
    echo '</form>';
?>
                </td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr class="dataTableHeadingRow">
                <td class="dataTableHeadingContent"><a href="<?php echo tep_href_link(FILENAME_GIFT_CARDS, 'sort=g.gift_cards_amount_remaining'); ?>"><?php echo TABLE_HEADING_GIFT_CARD_AMOUNT_REMAINING; ?></a></td>
                <td class="dataTableHeadingContent"><a href="<?php echo tep_href_link(FILENAME_GIFT_CARDS, 'sort=g.gift_cards_amount'); ?>"><?php echo TABLE_HEADING_GIFT_CARD_INITAL_AMOUT; ?></a></td>
                <td class="dataTableHeadingContent"><a href="<?php echo tep_href_link(FILENAME_GIFT_CARDS, 'sort=g.gift_cards_code'); ?>"><?php echo TABLE_HEADING_GIFT_CARD_CODE; ?></a></td>
				<td class="dataTableHeadingContent"><a href="<?php echo tep_href_link(FILENAME_GIFT_CARDS, 'sort=c.customers_lastname'); ?>"><?php echo TABLE_HEADING_GIFT_CARD_PURCHASER; ?></a></td>
				<td class="dataTableHeadingContent"><a href="<?php echo tep_href_link(FILENAME_GIFT_CARDS, 'sort=g.gift_cards_enabled'); ?>"><?php echo TABLE_HEADING_GIFT_CARD_ENABLED; ?></a></td>
              </tr>
			  <?php
			  $parameters = array('gift_cards_id' => '',
                                  'gift_cards_amount' => '',
                                  'gift_cards_amount_remaining' => '',
                                  'gift_cards_code' => '',
                                  'orders_products_id' => '',
                                  'purchaser' => '',
                                  'gift_cards_enabled' => '');

              $gcInfo = new objectInfo($parameters);
			  
			  // gather the gift cards
			  $clause = ' ';
			  if (isset($HTTP_GET_VARS['sort']) && ($HTTP_GET_VARS['sort'] != '')) {
			    $clause .= 'ORDER BY '.$HTTP_GET_VARS['sort'];
			  }
			  $gift_card_query = tep_db_query("select * from `".TABLE_GIFT_CARDS."` g left join `".TABLE_CUSTOMERS."` c on c.customers_id=g.purchaser".$clause);
			  $gift_card_count = 0;
			  while($gift_card = tep_db_fetch_array($gift_card_query)) {
			    $gift_card_count++;
				if (($gift_card_count == 1) && (!$gID)) {
				  $gID = $gift_card['gift_cards_id'];
				}
				if ($gID == $gift_card['gift_cards_id']) {
				  $gcInfo->objectInfo($gift_card);
				  echo '              <tr id="defaultSelected" class="dataTableRowSelected" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_GIFT_CARDS, 'gID=' . $gift_card['gift_cards_id']) . '\'">' . "\n";
				} else {
			      echo '<tr class="dataTableRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" onclick="document.location.href=\'' . tep_href_link(FILENAME_GIFT_CARDS, 'gID=' . $gift_card['gift_cards_id']) . '\'">'."\n";
				}
				echo '  <td class="dataTableContent">'.$gift_card['gift_cards_amount_remaining'].'</td>'."\n";
				echo '  <td class="dataTableContent">'.$gift_card['gift_cards_amount'].'</td>'."\n";
				echo '  <td class="dataTableContent">'.$gift_card['gift_cards_code'].'</td>'."\n";
				if ($gift_card['customers_lastname'] != '') {
				  echo '  <td class="dataTableContent">'.$gift_card['customers_lastname'].', '.$gift_card['customers_firstname'].'</td>'."\n";
				} else {
				  echo '  <td class="dataTableContent"></td>'."\n";
				}
				if ($gift_card['gift_cards_enabled'] == '1') {
				  echo '  <td class="dataTableContent">Enabled</td>'."\n";
				} else {
				  echo '  <td class="dataTableContent">Disabled</td>'."\n";
				}
				echo '</tr>';
			  }
			  ?>
			</table>
			</td>
			<td valign="top">
			<?php
			$heading = array();
			$heading[] = array('text' => '<b>Edit Gift Card</b>');
			
			$contents = array('form' => tep_draw_form('edit', FILENAME_GIFT_CARDS, 'action=edit') . tep_draw_hidden_field('gift_card_id', $gID));
            $contents[] = array('text' => TEXT_INFO_EDIT_INTRO);
			$radio1 = true;
			$radio2 = false;
			if (!$gcInfo->gift_cards_enabled) {
			  $radio1 = false;
			  $radio2 = true;
			}
            $contents[] = array('text' => '<br>' . TEXT_ENABLED_INTRO . '<br><label>' . tep_draw_radio_field('gc_enable', 'enable', $radio1) . ' ' . TEXT_ENABLED . '</label><br><label>' . tep_draw_radio_field('gc_enable', 'disable', $radio2) . ' ' . TEXT_DISABLED.'</label>');
			$contents[] = array('text' => 'Change Remaining Amount:<br />'.tep_draw_input_field('gc_new_amount', $gcInfo->gift_cards_amount_remaining));
		
            $contents[] = array('align' => 'center', 'text' => '<br>' . tep_image_submit('button_save.gif', IMAGE_COPY) . ' <a href="' . tep_href_link(FILENAME_GIFT_CARDS) . '">' . tep_image_button('button_cancel.gif', IMAGE_CANCEL) . '</a>');
		
			if ( (tep_not_null($heading)) && (tep_not_null($contents)) ) {
              $box = new box;
              echo $box->infoBox($heading, $contents);
            }
			?>
			</td>
		  </tr>
		</table>
		</td>
      </tr>
	</table>
    </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
